<?php


namespace app\queue\stomp;


use app\queue\BaseConsumer;
use common\model\EntityModel;
use common\observer\TaskExecutorTypeSyncToEntity;

/**
 * 检查实体的是否外包状态
 */
class CheckEntityIsOutsourceStatusConsumer extends BaseConsumer
{
    // 要消费的队列名
    public $queue = 'check_entity_is_outsource_status';

    // 连接名，对应 config/redis_queue.php 里的连接`
    public $connection = 'default';

    public function doConsume($data)
    {
        if (empty($data['entity_ids'])) {
            return;
        }
        $entityList = model(EntityModel::class)->where(['id' => ['IN', $data['entity_ids']]])->select();
        foreach ($entityList as $entity) {
            try {
                TaskExecutorTypeSyncToEntity::getInstance()->checkEntityIsOutsourceStatus($entity);
            } catch (\Throwable $e) {
                trace(format_exception_info($e), 'ERR');
            }
        }

    }
}
